<include file="public@header"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <form id="submitForm" class="well form-inline margin-top-20" method="post" action="{:url('Wechat/tagList')}">
        <!--时间:-->
        <!--<input type="text" class="form-control js-bootstrap-datetime" name="start_time"-->
        <!--value="{$start_time|default=''}"-->
        <!--style="width: 140px;" autocomplete="off">- -->
        <!--<input type="text" class="form-control js-bootstrap-datetime" name="end_time"-->
        <!--value="{$end_time|default=''}"-->
        <!--style="width: 140px;" autocomplete="off"> &nbsp; &nbsp;-->
        关键字:
        <input type="text" class="form-control" name="keyword" style="width: 200px;"
               value="{$keyword|default=''}" placeholder="请输入关键字...">
        <input type="submit" class="btn btn-primary" value="搜索"/>
        <a class="btn btn-danger"  href="{:url('Wechat/tagList')}" >清空</a>

        <a class="btn btn-danger"  href="{:url('Wechat/updateTag')}" >同步标签</a><br/><br/>
        <label class="form-required">若您的标签较多，请耐心等待，直到出现“同步完成”才是同步标签成功</label><br/>
        <label class="form-required">更改完备注之后，建议进行一次【同步标签】，防止出错</label>
    </form>


    <span class="btn btn-primary" onclick="addTag()">添加标签</span><br/><br/>
    <form class="js-ajax-form" action="" method="post">
        <table class="table table-hover table-bordered table-list">
            <thead>
            <tr>
                <th width="15">
                    <label>
                        <input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
                    </label>
                </th>
                <notempty name="category">
                    <th width="50">{:lang('SORT')}</th>
                </notempty>
                <th>标签名称</th>
                <th>粉丝数量</th>
                <th>点击查看</th>
                <th>操作</th>
            </tr>
            </thead>
            <notempty name="list">
                <foreach name="list" item="vo">
                <tr>
                    <td>
                        <input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]"
                               value="{$vo.id}" title="ID:{$vo.id}">
                    </td>
                    <td>
                        <a href="javascript:;" class="caname">{$vo.name}</a>
                        <input type="hidden" name="tag_id" value="{$vo.tagid_list}">
                    </td>
                    <td>{$vo.count}</td>
                    <td><a href="{:url('admin/Wechat/fansList',['tagid_list'=>$vo.tagid_list])}">点击查看</a></td>
                    <td><a href="javascript:;" onclick="delTag({$vo.tagid_list})">删除</a></td>
                </tr>
            </foreach>
            </notempty>
            <tfoot>
            <tr>
                <th width="15">
                    <label>
                        <input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
                    </label>
                </th>
                <notempty name="category">
                    <th width="50">{:lang('SORT')}</th>
                </notempty>
                <th>标签名称</th>
                <th>粉丝数量</th>
                <th>点击查看</th>
                <th>操作</th>
            </tr>
            </tfoot>
        </table>
        <ul class="pagination">{$page|default=''}</ul>
    </form>
</div>
<script src="__STATIC__/js/admin.js"></script>
<script>

    function addTag() {
        layer.prompt({title: '输入要添加的标签', formType: 0}, function(text, index){
            $.ajax({
                type: "POST",
                url: "{:url('Wechat/addTag')}",
                data: {text:text},
                dataType:"json",
                success: function(data){
                    layer.msg(data.msg, {
                        icon: 1,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function(){
                        window.location.href = "{:url('Wechat/updateTag')}";
                    });
                }
            });
            layer.close(index);
        });
    }

    function delTag(tagId) {
        layer.confirm('确定删除标签？', {icon: 3, title:'提示'}, function(index){
            $.ajax({
                type: "POST",
                url: "{:url('Wechat/delTag')}",
                data: {tagId:tagId},
                dataType:"json",
                success: function(data){
                    layer.msg(data.msg, {
                        icon: 1,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function(){
                        window.location.reload();
                    });
                }
            });
            layer.close(index);
        });
    }
    function reloadPage(win) {
        win.location.reload();
    }
    $(function() {
        $(".caname").click(function() {
            var td = $(this);
            var txt = td.text();
            var input = $("<input type='text' value='"+txt+"'/>");
            td.html(input);
            input.click(function() { return false; });
//获取焦点
            input.trigger("focus");
//文本框失去焦点后提交内容，重新变为文本
            input.blur(function() {
                var newtxt = $(this).val();
                if(newtxt == ''){
                    td.html(txt);
                }else if(newtxt == txt){
                    td.html(txt);
                }else{
                    td.html(newtxt);
                    var tag_id=td.siblings().val();
                    $.ajax({
                        type: "POST",
                        url: "{:url('Wechat/changeTag')}",
                        data: {name:newtxt,tagid_list:tag_id},
                        dataType:"json",
                        success: function(data){
                            layer.msg(data.msg);
                        }
                    });
                }
            });
        });
    });
</script>
</body>
</html>